# Maintainer: Massimiliano Torromeo <massimiliano.torromeo@gmail.com>
# Contributor: Pierre Schmitz <pierre@archlinux.de>

pkgname=openfire
pkgver=4.7.4
pkgrel=1
pkgdesc="High performance XMPP (Jabber) server."
arch=('any')
url='https://www.igniterealtime.org/projects/openfire/'
license=('APACHE')
depends=('java-runtime-headless<19')
makedepends=('maven' 'jre11-openjdk-headless' 'jdk11-openjdk')
backup=('etc/conf.d/openfire'
        'etc/openfire/openfire.xml'
        'etc/openfire/security.xml'
        'etc/openfire/crowd.properties'
        'etc/openfire/security/truststore'
        'etc/openfire/security/client.truststore'
        'etc/openfire/security/keystore')
source=("$pkgname-$pkgver.tar.gz::https://github.com/igniterealtime/Openfire/archive/refs/tags/v$pkgver.tar.gz"
        'openfire.conf'
        'openfire.service'
        'user.conf'
        'tmpfile.conf')
sha256sums=('5eb22e165d1de0a1e601efbd356266a6823fafc866b684500ec90af1ba764ab9'
            'c8a612abee90bdc9a2869e562a4bbbf596159c60adcd23368833a0e2ca27c1d4'
            '3e7bca77161777daefd3533d4d6f42ff7970533c887d6f4b7f1c9fdcf7771d05'
            '8bfa51cf8cc88fc69547a8f6e9e3fb242926ca2a100659363e1a6b332f223ba9'
            'c63396991984a067d05e21094a664255d6aed2bf294bddd3885a7da75472b886')

build() {
	cd "$srcdir"/Openfire-$pkgver
	make
}

package() {
	cd "$pkgdir"
	install -dm755 usr/lib usr/share/openfire/resources usr/share/doc
	install -dm750 etc/openfire

	cd "$srcdir"
	install -Dm644 openfire.conf "$pkgdir"/etc/conf.d/openfire
	install -Dm644 openfire.service "$pkgdir"/usr/lib/systemd/system/openfire.service
	install -Dm644 user.conf "$pkgdir"/usr/lib/sysusers.d/openfire.conf
	install -Dm644 tmpfile.conf "$pkgdir"/usr/lib/tmpfiles.d/openfire.conf

	cd Openfire-$pkgver/distribution/target/distribution-base

	cp -R conf/* "$pkgdir"/etc/openfire/

	cp -R resources/security "$pkgdir"/etc/openfire/
	ln -s /etc/openfire/security "$pkgdir"/usr/share/openfire/resources/security

	cp -R plugins "$pkgdir"/usr/share/openfire/
	cp -R resources/{database,spank,nativeAuth} "$pkgdir"/usr/share/openfire/resources/
	rm -rf "$pkgdir"/usr/share/openfire/resources/nativeAuth/{osx,win}*
	cp -R lib "$pkgdir"/usr/lib/openfire
	cp -R documentation "$pkgdir"/usr/share/doc/openfire
}
